const Router = require('koa-router')
const together = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
    database: 'running',
    user: 'run',
    port: 5432,
    host: '82.157.94.115',
    password: 'z12345678',
    max: 2
  })

together.post('/together', async ctx => {
    // ctx.body = ''
    let {activityname, location,effectivetime,peoplenum,content,realname,contactvalue} = ctx.request.body;
    console.log("activityname",activityname);
    console.log("location",location);
    console.log("effectivetime",effectivetime);
    console.log("peoplenum",peoplenum);
    console.log("content",content);
    console.log("realname",realname);

    let insertContentPostgresql = `insert into together (activityname, location,effectivetime,peoplenum,realname,content,contactvalue) `
        + `values ('${activityname}','${location}', '${effectivetime}', ${peoplenum},'${realname}','${content}','${contactvalue}')`;

    let togetherContent = await psql.query(insertContentPostgresql);

    if (togetherContent.rowCount > 0)
        ctx.body = {
            activityname:activityname, 
            location:location,
            effectivetime:effectivetime,
            peoplenum:peoplenum,
            realname:realname,
            content:content,
            contactvalue:contactvalue
            
        };
})

module.exports = together